<!--
* description: 销售顾问
* author: zouzx
* createdDate: 2019-10-24
-->
<template>
  <section class="carTypeConfig">
    <el-dialog
      v-dialogDrag
      title="节点组"
      :visible.sync="curPopupsVisible"
      width="1000px"
      center
      @close="sendCode"
      :close-on-click-modal="false"
      :append-to-body="true"
      ref="dialogMultipleTable"
    >
      <dialogHeader slot="title" :title="'节点组'" :styleType="$store.state.app.dialogType"></dialogHeader>
      <one-table-template
        ref="multipleTable"
        :dynamicButtons="tableButtons"
        :dynamicComponents="tableComponents"
        :dynamicApiConfig="apiConfig"
        :dynamicTableCols="tableCols"
        :dynamicFormFields="formField"
        :dynamicIsShowSelect="isMul"
        :key="popupsTableKey"
      />
    </el-dialog>
  </section>
</template>
<script>
import { oneTableWithViewTemplateMixins } from "@/components/mixins/oneTableWithViewTemplateMixins";
import { valueObjectMixins } from "@/components/mixins/valueObjectMixins";
import { crmApis } from "@/api/apiList/crm";
import OneTableTemplate from "@/components/crm/commonComponents/crmPopupsOneTable";
export default {
  // 组件混入对象：{data[listQuery] methods[queryTable]}
  mixins: [oneTableWithViewTemplateMixins, valueObjectMixins],
  components: {
    OneTableTemplate,
    dialogHeader: () => import("@/components/dialogHeader") //弹窗标题
  },
  data() {
    return {
      // 网格查询API配置对象
      apiConfig: crmApis.csDbNodeGroupQueryFindAll,
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: "btnKey1",
          type: "primary",
          size: "small",
          clickEvent: () => this.queryTable(1),
          text: "查询",
          position: "top"
        },
        {
          compKey: "btnKey2",
          type: "primary",
          size: "small",
          clickEvent: () => this.sendCode(this.codeField, "groupName"),
          text: "确认",
          position: "bottom"
        },
        {
          compKey: "btnKey3",
          type: "",
          size: "small",
          clickEvent: () => this.reset(),
          text: "重置",
          position: "top"
        }
      ],
      // 动态组件-查询条件
      tableComponents: [
        // 显示组件
        {
          compKey: "compKey1",
          labelName: "业务流程",
          codeField: "serverType",
          lookuptype: "LX009",
          component: () => import("@/components/crm/lookupValue/lookupvalue"),
          type: "dropdownList",
          isMust: true,
          isMul: false
        },
        {
          compKey: "compKey2",
          labelName: "节点组名称",
          codeField: "nodeGroupName",
          component: () => import("@/components/crm/textbox/crmTextInput"),
          type: "inputText",
          isMust: true
        }
      ],
      // 动态生成网格列
      tableCols: [
        {
          prop: "serverTypeName",
          label: "业务流程",
          width: null,
          align: "center"
        },
        {
          prop: "nodeGroupCode",
          label: "节点组编码",
          width: null,
          align: "center"
        },
        {
          prop: "groupName",
          label: "节点组名称",
          width: null,
          align: "center"
        },
        {
          prop: "serverType",
          label: "业务流程编码",
          width: null,
          align: "center",
          hidden: true
        }
      ],
      //表单查询数据（查询条件）
      formField: {
        oemCode: "1",
        groupCode: "1",
        serverType: "",
        nodeGroupName: ""
      },
            //双击事件
      handleTableRowData:{
        value:this.codeField,
        text:"groupName"
      }
    };
  },
  methods: {
    sendCode(arrayCodeField, arrayTextField) {
      // 获取嵌套组件的选中的值
      debugger;
      const that = this.$refs.multipleTable;
      const selectData = [];
      if (this.isMul == true) {
        selectData = this.$refs.multipleTable.selection;
      } else {
        selectData.push(this.$refs.multipleTable.currentRow);
      }
      if (selectData && selectData.length > 0) {
        let tmpCodeField = arrayCodeField;
        let tmpTextField = arrayTextField;
        this.modelCode = this.$utils.getArrayFromJsonArray(
          selectData,
          tmpCodeField
        );
        this.modelText = this.$utils.getArrayFromJsonArray(
          selectData,
          tmpTextField
        );
      } else {
        this.modelCode = [];
        this.modelText = [];
      }
      var code =
        typeof this.modelCode === "string"
          ? this.modelCode
          : this.modelCode.join(",");
      var text =
        typeof this.modelText === "string"
          ? this.modelText
          : this.modelText.join(",");
      this.$emit(
        "changeCode",
        code,
        text,
        this.codeField,
        this.comType,
        this.popupsKey,
        this.textField,
        this.otherField,
        selectData
      );
    }
  }
};
</script>
